package com.wyl.config;

import javax.servlet.ServletContext;

import org.springframework.core.annotation.Order;
import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.multipart.support.MultipartFilter;

import com.wyl.interceptor.TokenInterceptor;
/**
 * spring安全验证类
  * @ClassName: WebAppSecurityInitializer
  * @Description: TODO
  * @author sunkxu
  * @date 2014年6月6日 下午12:03:39
 */
@Order(3)
public class WebAppSecurityInitializer extends AbstractSecurityWebApplicationInitializer {
	/*
	 * If you are not using Spring or Spring MVC, you will need to pass in the SecurityConfig into the superclass to ensure the configuration is picked up. You can find an example below:
	 */
	/*
	public WebAppSecurityInitializer() {
        super(SecurityConfig.class);
    }*/
	/*
	 * 在进入安全链前，先对字符编码转成UTF8, 对文件上传做设置
	  * <p>Title: beforeSpringSecurityFilterChain</p>
	  * <p>Description: </p>
	  * @param servletContext
	  * @see org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer#beforeSpringSecurityFilterChain(javax.servlet.ServletContext)
	 */
	@Override
    protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        
        //HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
        
		insertFilters(servletContext, characterEncodingFilter);
		//servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null ,true, "/*");
	
		//insertFilters(servletContext, characterEncodingFilter);
		//文件上传　
        insertFilters(servletContext, new MultipartFilter());

    }
}